import Vue from 'vue'
import App from './App.vue'
import router from './router'

import './assets/css/global.css'
import TreeTable from 'vue-table-with-tree-grid'

import axios from 'axios'
// 导入富文本编辑器
import VueQullEditor from 'vue-quill-editor'

// 导入nprogress
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

// 配置请求根路径
axios.defaults.baseURL = 'http://127.0.0.1:8888/api/private/v1'

/**
 * 拦截器配置
 */
// 在request拦截器中展示进度条、添加token
axios.interceptors.request.use(config => {
    NProgress.start()
    // config
    config.headers.Authorization = window.sessionStorage.getItem('token')
    return config
})

// 在response拦截器中隐藏进度条
axios.interceptors.response.use(config => {
    NProgress.done()
    return config
})

Vue.prototype.$http = axios

Vue.config.productionTip = false

Vue.component('tree-table', TreeTable)
// 全局过滤器 过滤时间戳
Vue.filter('dateFormat', originVal => {
    const dt = new Date(originVal)
    const yyyy = dt.getFullYear()
    const MM = (dt.getMonth() + 1 + '').padStart(2, '0')
    const dd = (dt.getDate() + '').padStart(2, '0')
    const hh = (dt.getHours() + '').padStart(2, '0')
    const mm = (dt.getMinutes() + '').padStart(2, '0')
    const ss = (dt.getSeconds() + '').padStart(2, '0')
    return `${yyyy}-${MM}-${dd} ${hh}:${mm}:${ss}`
})

Vue.use(VueQullEditor)

new Vue({
    router,
    render: h => h(App)
}).$mount('#app')
